define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activity/activitylist/index' + location.search,
                    add_url: 'activity/activitylist/add',
                    edit_url: 'activity/activitylist/edit',
                    del_url: 'activity/activitylist/del',
                    detail_url: 'activity/activitylist/detail',
                    multi_url: 'activity/activitylist/multi',
                    import_url: 'activity/activitylist/import',
                    table: 'events',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('活动的名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_time', title: __('活动的开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end_time', title: __('活动的结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'winner_team_text', title: __('活动结束后的获胜队伍')},
                        {field: 'created_at', title: __('记录创建时间')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        buttons: [
                            {
                                name: 'detail',
                                text: __('添加获胜队伍'),
                                title: __('添加获胜队伍'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                url: 'activity/activitylist/detail',
                                visible: function (row) {
                                    if(row.status == 0) {
                                        return true;
                                    }
                                    return false
                                }
                            },
                            {
                                name: 'detail',
                                text: __('添加队伍'),
                                title: __('添加队伍'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                url: 'activity/rankslist/add',
                            },
                            {
                                name: 'detail',
                                text: __('查看参与用户'),
                                title: __('查看参与用户'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                url: 'activity/userlist?ids={ids}',
                
                            },
                
                        ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
